home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / managers / LayoutManager.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  15.0 KB  |  437 lines

  1. package mx.managers
  2. {
  3.    import flash.display.Stage;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import mx.core.ApplicationGlobals;
  7.    import mx.core.UIComponent;
  8.    import mx.core.mx_internal;
  9.    import mx.events.FlexEvent;
  10.    import mx.managers.layoutClasses.PriorityQueue;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class LayoutManager extends EventDispatcher implements ILayoutManager
  15.    {
  16.       private static var instance:LayoutManager;
  17.       
  18.       mx_internal static const VERSION:String = "3.2.0.3958";
  19.       
  20.       private var invalidateClientPropertiesFlag:Boolean = false;
  21.       
  22.       private var invalidateDisplayListQueue:PriorityQueue;
  23.       
  24.       private var updateCompleteQueue:PriorityQueue;
  25.       
  26.       private var invalidateDisplayListFlag:Boolean = false;
  27.       
  28.       private var invalidateClientSizeFlag:Boolean = false;
  29.       
  30.       private var invalidateSizeQueue:PriorityQueue;
  31.       
  32.       private var originalFrameRate:Number;
  33.       
  34.       private var invalidatePropertiesFlag:Boolean = false;
  35.       
  36.       private var invalidatePropertiesQueue:PriorityQueue;
  37.       
  38.       private var invalidateSizeFlag:Boolean = false;
  39.       
  40.       private var callLaterPending:Boolean = false;
  41.       
  42.       private var _usePhasedInstantiation:Boolean = false;
  43.       
  44.       private var callLaterObject:UIComponent;
  45.       
  46.       private var targetLevel:int = 2147483647;
  47.       
  48.       public function LayoutManager()
  49.       {
  50.          updateCompleteQueue = new PriorityQueue();
  51.          invalidatePropertiesQueue = new PriorityQueue();
  52.          invalidateSizeQueue = new PriorityQueue();
  53.          invalidateDisplayListQueue = new PriorityQueue();
  54.          super();
  55.       }
  56.       
  57.       public static function getInstance() : LayoutManager
  58.       {
  59.          if(!instance)
  60.          {
  61.             instance = new LayoutManager();
  62.          }
  63.          return instance;
  64.       }
  65.       
  66.       public function set usePhasedInstantiation(param1:Boolean) : void
  67.       {
  68.          var sm:ISystemManager = null;
  69.          var stage:Stage = null;
  70.          var value:Boolean = param1;
  71.          if(_usePhasedInstantiation != value)
  72.          {
  73.             _usePhasedInstantiation = value;
  74.             try
  75.             {
  76.                sm = SystemManagerGlobals.topLevelSystemManagers[0];
  77.                stage = SystemManagerGlobals.topLevelSystemManagers[0].stage;
  78.                if(stage)
  79.                {
  80.                   if(value)
  81.                   {
  82.                      originalFrameRate = stage.frameRate;
  83.                      stage.frameRate = 1000;
  84.                   }
  85.                   else
  86.                   {
  87.                      stage.frameRate = originalFrameRate;
  88.                   }
  89.                }
  90.             }
  91.             catch(e:SecurityError)
  92.             {
  93.             }
  94.          }
  95.       }
  96.       
  97.       private function waitAFrame() : void
  98.       {
  99.          callLaterObject.callLater(doPhasedInstantiation);
  100.       }
  101.       
  102.       public function validateClient(param1:ILayoutManagerClient, param2:Boolean = false) : void
  103.       {
  104.          var _loc3_:ILayoutManagerClient = null;
  105.          var _loc4_:int = 0;
  106.          var _loc5_:Boolean = false;
  107.          var _loc6_:int = targetLevel;
  108.          if(targetLevel == int.MAX_VALUE)
  109.          {
  110.             targetLevel = param1.nestLevel;
  111.          }
  112.          while(!_loc5_)
  113.          {
  114.             _loc5_ = true;
  115.             _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  116.             while(_loc3_)
  117.             {
  118.                _loc3_.validateProperties();
  119.                if(!_loc3_.updateCompletePendingFlag)
  120.                {
  121.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  122.                   _loc3_.updateCompletePendingFlag = true;
  123.                }
  124.                _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  125.             }
  126.             if(invalidatePropertiesQueue.isEmpty())
  127.             {
  128.                invalidatePropertiesFlag = false;
  129.                invalidateClientPropertiesFlag = false;
  130.             }
  131.             _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  132.             while(_loc3_)
  133.             {
  134.                _loc3_.validateSize();
  135.                if(!_loc3_.updateCompletePendingFlag)
  136.                {
  137.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  138.                   _loc3_.updateCompletePendingFlag = true;
  139.                }
  140.                if(invalidateClientPropertiesFlag)
  141.                {
  142.                   _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  143.                   if(_loc3_)
  144.                   {
  145.                      invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  146.                      _loc5_ = false;
  147.                      break;
  148.                   }
  149.                }
  150.                _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  151.             }
  152.             if(invalidateSizeQueue.isEmpty())
  153.             {
  154.                invalidateSizeFlag = false;
  155.                invalidateClientSizeFlag = false;
  156.             }
  157.             if(!param2)
  158.             {
  159.                _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  160.                while(_loc3_)
  161.                {
  162.                   _loc3_.validateDisplayList();
  163.                   if(!_loc3_.updateCompletePendingFlag)
  164.                   {
  165.                      updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  166.                      _loc3_.updateCompletePendingFlag = true;
  167.                   }
  168.                   if(invalidateClientPropertiesFlag)
  169.                   {
  170.                      _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  171.                      if(_loc3_)
  172.                      {
  173.                         invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  174.                         _loc5_ = false;
  175.                         break;
  176.                      }
  177.                   }
  178.                   if(invalidateClientSizeFlag)
  179.                   {
  180.                      _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  181.                      if(_loc3_)
  182.                      {
  183.                         invalidateSizeQueue.addObject(_loc3_,_loc3_.nestLevel);
  184.                         _loc5_ = false;
  185.                         break;
  186.                      }
  187.                   }
  188.                   _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  189.                }
  190.                if(invalidateDisplayListQueue.isEmpty())
  191.                {
  192.                   invalidateDisplayListFlag = false;
  193.                }
  194.             }
  195.          }
  196.          if(_loc6_ == int.MAX_VALUE)
  197.          {
  198.             targetLevel = int.MAX_VALUE;
  199.             if(!param2)
  200.             {
  201.                _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  202.                while(_loc3_)
  203.                {
  204.                   if(!_loc3_.initialized)
  205.                   {
  206.                      _loc3_.initialized = true;
  207.                   }
  208.                   _loc3_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  209.                   _loc3_.updateCompletePendingFlag = false;
  210.                   _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  211.                }
  212.             }
  213.          }
  214.       }
  215.       
  216.       private function validateProperties() : void
  217.       {
  218.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  219.          while(_loc1_)
  220.          {
  221.             _loc1_.validateProperties();
  222.             if(!_loc1_.updateCompletePendingFlag)
  223.             {
  224.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  225.                _loc1_.updateCompletePendingFlag = true;
  226.             }
  227.             _loc1_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  228.          }
  229.          if(invalidatePropertiesQueue.isEmpty())
  230.          {
  231.             invalidatePropertiesFlag = false;
  232.          }
  233.       }
  234.       
  235.       public function invalidateProperties(param1:ILayoutManagerClient) : void
  236.       {
  237.          if(!invalidatePropertiesFlag && Boolean(ApplicationGlobals.application.systemManager))
  238.          {
  239.             invalidatePropertiesFlag = true;
  240.             if(!callLaterPending)
  241.             {
  242.                if(!callLaterObject)
  243.                {
  244.                   callLaterObject = new UIComponent();
  245.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  246.                   callLaterObject.callLater(waitAFrame);
  247.                }
  248.                else
  249.                {
  250.                   callLaterObject.callLater(doPhasedInstantiation);
  251.                }
  252.                callLaterPending = true;
  253.             }
  254.          }
  255.          if(targetLevel <= param1.nestLevel)
  256.          {
  257.             invalidateClientPropertiesFlag = true;
  258.          }
  259.          invalidatePropertiesQueue.addObject(param1,param1.nestLevel);
  260.       }
  261.       
  262.       public function invalidateDisplayList(param1:ILayoutManagerClient) : void
  263.       {
  264.          if(!invalidateDisplayListFlag && Boolean(ApplicationGlobals.application.systemManager))
  265.          {
  266.             invalidateDisplayListFlag = true;
  267.             if(!callLaterPending)
  268.             {
  269.                if(!callLaterObject)
  270.                {
  271.                   callLaterObject = new UIComponent();
  272.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  273.                   callLaterObject.callLater(waitAFrame);
  274.                }
  275.                else
  276.                {
  277.                   callLaterObject.callLater(doPhasedInstantiation);
  278.                }
  279.                callLaterPending = true;
  280.             }
  281.          }
  282.          else if(!invalidateDisplayListFlag && !ApplicationGlobals.application.systemManager)
  283.          {
  284.          }
  285.          invalidateDisplayListQueue.addObject(param1,param1.nestLevel);
  286.       }
  287.       
  288.       private function validateDisplayList() : void
  289.       {
  290.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  291.          while(_loc1_)
  292.          {
  293.             _loc1_.validateDisplayList();
  294.             if(!_loc1_.updateCompletePendingFlag)
  295.             {
  296.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  297.                _loc1_.updateCompletePendingFlag = true;
  298.             }
  299.             _loc1_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  300.          }
  301.          if(invalidateDisplayListQueue.isEmpty())
  302.          {
  303.             invalidateDisplayListFlag = false;
  304.          }
  305.       }
  306.       
  307.       public function validateNow() : void
  308.       {
  309.          var _loc1_:int = 0;
  310.          if(!usePhasedInstantiation)
  311.          {
  312.             _loc1_ = 0;
  313.             while(callLaterPending && _loc1_++ < 100)
  314.             {
  315.                doPhasedInstantiation();
  316.             }
  317.          }
  318.       }
  319.       
  320.       private function validateSize() : void
  321.       {
  322.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  323.          while(_loc1_)
  324.          {
  325.             _loc1_.validateSize();
  326.             if(!_loc1_.updateCompletePendingFlag)
  327.             {
  328.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  329.                _loc1_.updateCompletePendingFlag = true;
  330.             }
  331.             _loc1_ = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  332.          }
  333.          if(invalidateSizeQueue.isEmpty())
  334.          {
  335.             invalidateSizeFlag = false;
  336.          }
  337.       }
  338.       
  339.       private function doPhasedInstantiation() : void
  340.       {
  341.          var _loc1_:ILayoutManagerClient = null;
  342.          if(usePhasedInstantiation)
  343.          {
  344.             if(invalidatePropertiesFlag)
  345.             {
  346.                validateProperties();
  347.                ApplicationGlobals.application.dispatchEvent(new Event("validatePropertiesComplete"));
  348.             }
  349.             else if(invalidateSizeFlag)
  350.             {
  351.                validateSize();
  352.                ApplicationGlobals.application.dispatchEvent(new Event("validateSizeComplete"));
  353.             }
  354.             else if(invalidateDisplayListFlag)
  355.             {
  356.                validateDisplayList();
  357.                ApplicationGlobals.application.dispatchEvent(new Event("validateDisplayListComplete"));
  358.             }
  359.          }
  360.          else
  361.          {
  362.             if(invalidatePropertiesFlag)
  363.             {
  364.                validateProperties();
  365.             }
  366.             if(invalidateSizeFlag)
  367.             {
  368.                validateSize();
  369.             }
  370.             if(invalidateDisplayListFlag)
  371.             {
  372.                validateDisplayList();
  373.             }
  374.          }
  375.          if(invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag)
  376.          {
  377.             callLaterObject.callLater(doPhasedInstantiation);
  378.          }
  379.          else
  380.          {
  381.             usePhasedInstantiation = false;
  382.             callLaterPending = false;
  383.             _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  384.             while(_loc1_)
  385.             {
  386.                if(!_loc1_.initialized && Boolean(_loc1_.processedDescriptors))
  387.                {
  388.                   _loc1_.initialized = true;
  389.                }
  390.                _loc1_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  391.                _loc1_.updateCompletePendingFlag = false;
  392.                _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  393.             }
  394.             dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  395.          }
  396.       }
  397.       
  398.       public function isInvalid() : Boolean
  399.       {
  400.          return invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag;
  401.       }
  402.       
  403.       public function get usePhasedInstantiation() : Boolean
  404.       {
  405.          return _usePhasedInstantiation;
  406.       }
  407.       
  408.       public function invalidateSize(param1:ILayoutManagerClient) : void
  409.       {
  410.          if(!invalidateSizeFlag && Boolean(ApplicationGlobals.application.systemManager))
  411.          {
  412.             invalidateSizeFlag = true;
  413.             if(!callLaterPending)
  414.             {
  415.                if(!callLaterObject)
  416.                {
  417.                   callLaterObject = new UIComponent();
  418.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  419.                   callLaterObject.callLater(waitAFrame);
  420.                }
  421.                else
  422.                {
  423.                   callLaterObject.callLater(doPhasedInstantiation);
  424.                }
  425.                callLaterPending = true;
  426.             }
  427.          }
  428.          if(targetLevel <= param1.nestLevel)
  429.          {
  430.             invalidateClientSizeFlag = true;
  431.          }
  432.          invalidateSizeQueue.addObject(param1,param1.nestLevel);
  433.       }
  434.    }
  435. }
  436.  
  437.